package pro.spring.controller.frontController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import pro.spring.model.Information;
import pro.spring.model.Users;
import pro.spring.vo.PaginationVo;


@Controller
@RequestMapping("index")
public class IndexController extends BaseController{
	
	//private String local = "page/front/index/";
	
	@RequestMapping(value="index.html",method=RequestMethod.GET)
	public String discussList(@RequestParam(value = "p", defaultValue = "1")Integer pagenum,ModelMap map,HttpServletRequest request,
			HttpServletResponse response,String key){
		HttpSession session=request.getSession();
		Integer uId = (Integer)session.getAttribute("uId");
		if(uId!=null){ 
			Users use = usersService.selectByPrimaryKey(uId);
			map.put("use", use);
			map.put("check",1);
			//视频分类推荐
			PaginationVo<Information> allvedio=youkuService.getPaginationInfo(0,12);
			PaginationVo<Information> allfile=yunService.getPaginationInfo(0,20);
			PaginationVo<Information> allart=informationService.getPaginationInfo(0,20);
			for(Information information:allart.getList()){
				information.setInContent(udiscusserService.getNOHTML(information.getInContent()));
			}
			map.put("allfile",allfile);
			map.put("allvedio",allvedio);
			map.put("allart",allart);
		}else{
			map.put("check",0);
			//视频默认推荐
			PaginationVo<Information> allvedio=youkuService.getPaginationInfo(0,12);
			PaginationVo<Information> allfile=yunService.getPaginationInfo(0,20);
			PaginationVo<Information> allart=informationService.getPaginationInfo(0,20);
			for(Information information:allart.getList()){
				information.setInContent(udiscusserService.getNOHTML(information.getInContent()));
			}
			map.put("allfile",allfile);
			map.put("allvedio",allvedio);
			map.put("allart",allart);
		}
		map.put("them",themeService.getPaginationInfo(key, pagenum,6));
		map.put("xian",udiscusserService.getXianxia(pagenum, 3));
		return "page/front/index/index";
	}
}
